aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/[username]/items/[id]/+page.server.js
blob: 4cfc952caa5befe9e0a73c28e41caca5daf52b00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { fd, auth, get, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";

export let load = async ({ cookies, params: { id } }) => {
  let item = await get(`/items/${id}`);
  return { item };
};

export const actions = {
  default: async ({ cookies, request, url }) => {
    let form = await fd(request);
    try {
      await post(`/items`, form, auth(cookies));
    } catch (e) {
      return fail(400, { message: e.message });
    }

    let success = `/${url.pathname.split("/")[1]}`;
    redirect(307, success);
  },
};